<?php

// declare(strict_types=1);

namespace app\common\AliYunOss;

use OSS\OssClient;
use OSS\Core\OssException;

class Common
{
    private static $instance = null;
    private static $endpoint ;
    private static $access_key_id ;
    private static $access_key_secret ;
    private static $bucket ;

    public static function init()
    {
        if (self::$access_key_id === null) {
            self::$access_key_id = config('filesystem.aliyun-oss.access_key_id');
            self::$access_key_secret = config('filesystem.aliyun-oss.access_key_secret');
            self::$endpoint = config('filesystem.aliyun-oss.endpoint');
            self::$bucket = config('filesystem.aliyun-oss.bucket');
        }
    }
    public static function getOssClientInstance()
    {
        if (self::$instance === null) {
            self::init();
            try {
                self::$instance = new OssClient(self::$access_key_id, self::$access_key_secret, self::$endpoint, false);
               
            } catch (OssException $e) {
                error_log(__FUNCTION__ . ": Creating OssClient instance: FAILED\n");
                error_log($e->getMessage() . "\n");
            }
        }
        return self::$instance;
    }
    public static function getBucketName()
    {
        return self::$bucket;
    }

    public static function getEndpoint()
    {
        return self::$endpoint;
    }
}
